walker.data.com

https://walker-data.com/posts/overture-buildings

Setup

if (!requireNamespace('arrow')) pak::pak("qfes/rdeck")
  install.packages('arrow', 
    repos = 'https://apache.r-universe.dev')

The downloaded binary packages are in
    /var/folders/hn/3nfdjww12237gp6y33bpnr7w0000gn/T//Rtmp78vaVE/downloaded_packages
library(arrow) 
# first load arrow then, _if_ needed, run install_arrow()
# install_arrow() 
arrow_info() # |> str(list.len = 3)
Arrow package version: 16.1.0

Capabilities:
               
acero      TRUE
dataset    TRUE
substrait FALSE
parquet    TRUE
json       TRUE
s3         TRUE
gcs        TRUE
utf8proc   TRUE
re2        TRUE
snappy     TRUE
gzip       TRUE
brotli     TRUE
zstd       TRUE
lz4        TRUE
lz4_frame  TRUE
lzo       FALSE
bz2        TRUE
jemalloc   TRUE
mimalloc   TRUE

Memory:
                  
Allocator mimalloc
Current    0 bytes
Max        0 bytes

Runtime:
                        
SIMD Level          none
Detected SIMD Level none

Build:
                                                             
C++ Library Version                                    16.1.0
C++ Compiler                                       AppleClang
C++ Compiler Version                          15.0.0.15000040
Git ID               7dd1d34074af176d9e861a360e135ae57b21cf96
stopifnot(
    arrow_available()
  , arrow_with_s3()
  , arrow_with_parquet()
  , arrow_with_json()
  , arrow_with_dataset()
  , arrow_with_gcs()
  # arrow_with_acero() , arrow_with_substrait()
)
if (!requireNamespace('rdeck')) 
  pak::pak("qfes/rdeck")
# remotes::install_github("qfes/rdeck")
if (!requireNamespace('pacman')) 
  install.packages("pacman")
pacman::p_load(
  sf, dplyr, tigris, rdeck,
  scales, tictoc, lobstr)
options(tigris_use_cache = TRUE)
s3_buildings <- 
  's3://overturemaps-us-west-2/release/2024-05-16-beta.0/theme=buildings?region=us-west-2'
tic('open_dataset')
  # database-like connection to the buildings dataset
  buildings <- open_dataset(s3_buildings)
toc()
open_dataset: 3.735 sec elapsed
lobstr::obj_size(buildings)
262.38 kB
tic('nrow(buildings)')
  num_buildings <- nrow(buildings) 
toc()
nrow(buildings): 168.52 sec elapsed
num_buildings |> prettyNum(big.mark = ',')
[1] "2,358,259,383"
num_buildings |> 
  scales::label_number(accuracy=0.1, 
    scale_cut=scales::cut_short_scale())(x = _)
[1] "2.4B"

London

  • {{bbox|-0.489|51.28|0.236|51.686}}
  • https://www.openstreetmap.org/export#map=15/51.5150/-0.0912
    • c(-0.1061, 51.5227, -0.0763, 51.5072)
  • http://bboxfinder.com/#0.000000,0.000000,0.000000,0.000000
    • -0.120450,51.509507,-0.076247,51.526465

SF

sf_bbox <- counties(state = "CA", cb = TRUE, resolution = "20m") |> 
  filter(NAME == "San Francisco") |> 
  st_bbox() |> 
  as.vector()
Retrieving data for the year 2022
sf_buildings <- buildings |>
  filter(bbox$xmin > sf_bbox[1],
         bbox$ymin > sf_bbox[2],
         bbox$xmax < sf_bbox[3],
         bbox$ymax < sf_bbox[4]) |>
  select(id, geometry, height) |> 
  collect() |>
  st_as_sf(crs = 4326) |> 
  mutate(height = ifelse(is.na(height), 8, height))
rdeck(map_style = mapbox_light(), 
      initial_view_state = view_state(
        center = c(-122.4657, 37.7548),
        zoom = 11.3,
        bearing = -60,
        pitch = 76
      )) |> 
  add_polygon_layer(
    data = sf_buildings, 
    name = "San Francisco",
    get_polygon = geometry, 
    get_elevation = height, 
    get_fill_color = scale_color_linear(
      col = height,
      palette = viridisLite::inferno(100, direction = -1)
    ),
    extruded = TRUE, 
    opacity = 0.5)
Warning in mapbox_access_token(): ! Assertion failed: length(tokens) == 0
! No mapbox access token found, mapbox basemap won't be shown.
ℹ Set mapbox token with one of:
• option `options(rdeck.mapbox_access_token = <token>)`
• environment variable `MAPBOX_ACCESS_TOKEN = <token>`
• environment variable `MAPBOX_TOKEN = <token>`
  
ℹ See <https://docs.mapbox.com/help/glossary/access-token>